package com.dlshouwen.core.base.dao;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Component;

/**
 * 框架首页数据
 *
 * @author cuixubin
 */
@Component("homeDao")
public class HomeDao extends BaseDao {
    /**
     * 注入数据源
     *
     * @param dataSource 数据源对象
     */
    @Resource(name = "defaultDataSource")
    public void setDataSource(DataSource dataSource) {
        super.setDataSource(dataSource);
    }

    /**网站管理后台最新新闻展示
     * 
     * @param newsNumber 要显示的新闻条数
     * @return 
     */
    public List<Map<String, Object>> getContentArtForHome(String newsNumber) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT album.album_coverpath,article.* ");
        sql.append("FROM wzgl_article article LEFT JOIN wzgl_album album ");
        sql.append("ON article.article_id = album.album_id ");
        sql.append("WHERE album.album_coverpath != NULL OR album.album_coverpath != '' ");
        sql.append("ORDER BY article.topset DESC, article.publish_time DESC ");
        sql.append("LIMIT 0," + newsNumber);
        return this.queryForList(sql.toString());
    }
}
